import { _decorator, Component, Label, Node, XrUIPressEvent } from 'cc';
import { UIBase } from './UIBase';
import { UIManager } from './UIManager';
import { XUtils } from '../comm/XUtils';
import { GameCtrl } from '../GameCtrl';
import { GameData } from '../GameData';
const { ccclass, property } = _decorator;

@ccclass('UILayer')
export class UILayer extends UIBase {
    

    @property(Label)
    mineText: Label;
    @property(Node)
    btnReturn: Node;
    @property(Node)
    btnLeft: Node;
    @property(Node)
    btnRight: Node;


    override onEnter(): void {
        super.onEnter();
        XUtils.bindButton(this.btnReturn,this.clickReturn,this);
        XUtils.bindButton(this.btnLeft,this.clickLeft,this);
        XUtils.bindButton(this.btnRight,this.clickRight,this);

        this.clickLeft();
        GameCtrl.Instance.isLeft = true;

        //this.setMineText();
    }

    override onExit(): void {
        super.onExit();
    }




    private clickLeft(){
        this.btnLeft.getChildByName('on').active = true;
        this.btnRight.getChildByName('on').active = false;
        GameCtrl.Instance.isLeft = true;
    }

    private clickRight(){
        this.btnLeft.getChildByName('on').active = false;
        this.btnRight.getChildByName('on').active = true;
        GameCtrl.Instance.isLeft = false;
    }

    private clickReturn(){
        this.onExit();
        GameCtrl.Instance.saveGame();
        //GameData.Instance.saveLevel(GameCtrl.Instance.currentLevel.level,GameCtrl.Instance.currentLevel);
        GameCtrl.Instance.UIGame.active = false;
        UIManager.Instance.openUI(UIManager.Instance.getUI('UIGameStart'));
    }

    public setMineText(){
        this.mineText.string = GameCtrl.Instance.currentLevel.mineNum;
    }
}


